package com.mygame;

import java.util.Random;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;

public class Sprite {
	
	private GameView gameView;
	private Bitmap bmp;
	private float x;
	private float y;
	private float width;
	private float height;
	private int Speed;
		
	
	public Sprite(GameView gameView, Bitmap bmp)
	{
		this.gameView = gameView;
		this.bmp = bmp;
		this.width = bmp.getWidth();
		this.height = bmp.getHeight();
		
		 Random rnd = new Random();
		 if (!Main.Landscape) {
			 while (true) {
				 x = rnd.nextInt(Main.horSizeScreen-Main.horSizeScreen/10)+5;
				 if (Math.abs(x-Main.horSizeScreen/2)<rnd.nextDouble()*Main.horSizeScreen/2) 
				   	break;
				        
			 }
			 while (true ) {
				 y = rnd.nextInt(Main.widthTrack)+Main.vertSizeScreen/2-Main.widthTrack/2;
				 if (Math.abs(y-Main.vertSizeScreen/2)<rnd.nextDouble()*Main.widthTrack/2)
					 break;
			 }
			
			 if (Math.abs(x-Main.horSizeScreen/2)>Main.horSizeScreen/2.5
					 || Math.abs(y-Main.vertSizeScreen/2)>Main.widthTrack/2.5)
				   this.bmp = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.small);
			 else
				 if (Math.abs(x-Main.horSizeScreen/2)>Main.horSizeScreen/3
						 || Math.abs(y-Main.vertSizeScreen/2)>Main.widthTrack/3)
					 this.bmp = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.middle);
		 }
		 else {
			 while (true) {
				 x = rnd.nextInt(Main.widthTrack)+Main.horSizeScreen/2-Main.widthTrack/2;
				 if (Math.abs(x-Main.horSizeScreen/2)<rnd.nextDouble()*Main.widthTrack/2) 
				   	break;
				        
			 }
			 while (true ) {
				 y = rnd.nextInt(Main.vertSizeScreen-Main.vertSizeScreen/11)+5;
				 if (Math.abs(y-Main.vertSizeScreen/2)<rnd.nextDouble()*Main.vertSizeScreen/2)
					 break;
			 }
			
			 if (Math.abs(x-Main.horSizeScreen/2)>Main.widthTrack/2.5
					 || Math.abs(y-Main.vertSizeScreen/2)>Main.vertSizeScreen/3)
				   this.bmp = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.small);
			 else
				 if (Math.abs(x-Main.horSizeScreen/2)>Main.widthTrack/3
						 || Math.abs(y-Main.vertSizeScreen/2)>Main.vertSizeScreen/4)
					 this.bmp = BitmapFactory.decodeResource(gameView.getResources(), R.drawable.middle);
			 
		 }
		
         Speed = 10;
	}
	
	public boolean isCollition(float x2, float y2)
    {
    	return x2 > x && x2 < x + width && y2 > y && y2 < y + height;
    }
	
		
	public void onDraw(Canvas canvas)
	{
		canvas.drawBitmap(bmp, x, y, null);
	}

	public float GetX()
	{
		return x;
	}
	
	public float GetY()
	{
		return y;
	}
	
	public float GetWidth()
	{
		return width;
	}
	
	public float GetHeight()
	{
		return height;
	}
}
